﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ERP_RORZE_DLL.Product.Base;
using ERP_RORZE_DLL.Product.DAO;
using ERP_RORZE_DLL.Product.database;

namespace ERP_RORZE.Product.PartData
{
    public partial class Frm_PartMaterialAdd : DevExpress.XtraEditors.XtraForm
    {
        ClsPartDataTable obj = new ClsPartDataTable();
        ClsPartDataDAO clspartDAO = new ClsPartDataDAO();
        DataTable dt;
        public EventHandler Re_Load;
        public Frm_PartMaterialAdd()
        {
            InitializeComponent();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Frm_PartMaterialAdd_Load(object sender, EventArgs e)
        {
            // lấy danh sách PartID truyền vào cbPartID
            dt = clspartDAO.GetAllPartID();
            cbPartID.DataSource = dt;
            cbPartID.DisplayMember = "PartNo";
            cbPartID.ValueMember = "PartNo";

            //Lấy danh sách MONo truyền vào cbMONo
            dt = clspartDAO.MaterialID();
            cbMaterialID.DataSource = dt;
            cbMaterialID.DisplayMember = "MaterialID";
            cbMaterialID.ValueMember = "MaterialID";
        }
        void ThongBao(string name)
        {
            MessageBox.Show("Chưa nhập " + name + ". Vui lòng nhập lại");
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (txtLenght.Text == "")
            {
                ThongBao(clsConstantsdb.Entities.ClsDBPartData.FieldName.lenght);
            }
            else if (txtMaterialType.Text == "")
            {
                ThongBao(clsConstantsdb.Entities.ClsDBPartData.FieldName.MaterialType);
            }
            else if (txtMemo.Text == "")
            {
                ThongBao(clsConstantsdb.Entities.ClsDBPartData.FieldName.Memo);
            }
            else if (txtNote.Text == "")
            {
                ThongBao(clsConstantsdb.Entities.ClsDBPartData.FieldName.Note);
            }
            else if (txtOtherpro.Text == "")
            {
                ThongBao(clsConstantsdb.Entities.ClsDBPartData.FieldName.Otherpro);
            }
            else if (txtPrice.Text == "")
            {
                ThongBao(clsConstantsdb.Entities.ClsDBPartData.FieldName.Price);
            }
            else if (txtShape.Text == "")
            {
                ThongBao(clsConstantsdb.Entities.ClsDBPartData.FieldName.shape);
            }
            else if (txtThickness.Text == "")
            {
                ThongBao(clsConstantsdb.Entities.ClsDBPartData.FieldName.Thickness);
            }
            else if (txtWidth.Text == "")
            {
                ThongBao(clsConstantsdb.Entities.ClsDBPartData.FieldName.width);
            }
            else if (txtWorkpiecesize.Text == "")
            {
                ThongBao(clsConstantsdb.Entities.ClsDBPartData.FieldName.Workpiecesize);
            }
            else
            {
                obj.InputDate = dateInputDate.Value;
                obj.PartID = cbPartID.Text;
                obj.MaterialID = cbMaterialID.Text;
                obj.Lenght = float.Parse(txtLenght.Text);
                obj.MaterialType = txtMaterialType.Text;
                obj.Memo = txtMemo.Text;
                obj.Note = txtNote.Text;
                obj.Otherpro = txtOtherpro.Text;
                obj.Price = int.Parse(txtPrice.Text);
                obj.Shape = txtShape.Text;
                obj.Thickness = float.Parse(txtThickness.Text);
                obj.Width = float.Parse(txtWidth.Text);
                obj.Workpiecesize = txtWorkpiecesize.Text;
                obj.Bafu = checkBafu.Checked;
                obj.BAnod = checkBAnod.Checked;
                obj.Blast30 = checkBlast30.Checked;
                obj.Blast60 = checkBlast60.Checked;
                obj.Caciras = checkCaciras.Checked;
                obj.Cleanwave = checkCleanwave.Checked;
                obj.Cut = checkCut.Checked;
                obj.HairLine = checkHairLine.Checked;
                obj.HandFinish = checkHandFinish.Checked;
                obj.Helisert = checkHelisert.Checked;
                obj.Inside = checkInside.Checked;
                obj.Migaki = checkMigaki.Checked;
                obj.PalCoat = checkPalCoat.Checked;
                obj.RawMachine = checkRawMachine.Checked;
                obj.Seal = checkSeal.Checked;
                obj.SerialNo = checkSeriaNo.Checked;
                obj.VacPac = checkVacPac.Checked;
                obj.WAnod = checkWAnod.Checked;
                clspartDAO.InsertPartMaterial(obj);
                this.Re_Load(sender, e);
            }
        }
    }
}